@isTest
private class CaseBlacklistController_Test
{
    
    public static CaseBlacklistController.blacklistWrapper getWrapper(List<CaseBlacklistController.blacklistWrapper> lbl,String email)
    {
        for (CaseBlacklistController.blacklistWrapper e : lbl)
        {
            if (e.bl.Email__c == email)
            {
                return e;
            }
        }
        return null;
    }
      
   
    public static void displayList(List<CaseBlacklistController.blacklistWrapper> lbl)
    {
        System.debug('*************************************************************');
        System.debug(lbl.size());
        for (CaseBlacklistController.blacklistWrapper e : lbl)
        {
            System.debug(e);
        }
        System.debug('*************************************************************');
    }
   
    public static testMethod void testCaseBlacklistController()
    {
        CaseBlacklistController blc = new CaseBlacklistController();
        // test the get blacklist
        
        List<CaseBlacklistController.blacklistWrapper> bl = blc.getBlacklist();
        Integer size1 = bl.size();
        displayList(bl);
        Integer addSize = CaseBlacklistHandler.add('blacklistunittest@salesforce.com');       
        List<CaseBlacklistController.blacklistWrapper> blackList = blc.getBlacklist();
        displayList(blackList);
        Integer size2 = blackList.size();        
        System.assertEquals(size1+1, size2);
        
        // test the addEmail functionality with a invalid email
        blc.setEmailString('flibbertygibbit');
        blc.addEmail();
        System.assertEquals(blc.getMessage(), 'invalid email');
        
        // now with a valid one
        blc.setEmailString('blacklistunittest2@salesforce.com');
        blc.addEmail();
        System.assertEquals(blc.getMessage(), '');
        List<CaseBlacklistController.blacklistWrapper> bl2 = blc.getBlacklist();
        System.assertEquals(blackList.size(), bl2.size());
        
        // test isDirty
        CaseBlacklistController.blacklistWrapper w = getWrapper(bl, 'blacklistunittest@salesforce.com');
        Boolean res = blc.isDirty(w);
        System.assertEquals(res, false);
        w.noReply = true;
        res = blc.isDirty(w);
        System.assertEquals(res, true);
        
        //make the change, test submitChanges
        blc.submitChanges();
        System.assertEquals(blc.getSubmitMessage(), 'Changes submitted');
        
       
                   
    }
    
   
}